import { getMaterialCodeList as getBaseGoodsList } from "@/api/process/mesProcessMaterial";
import { uniqueKey } from "@/utils/judge";
export const goodsDialog = {
  data() {
    return {
      goodsVisible: false, //表格弹框隐藏显示
      getBaseGoodsList, // 获取弹框数据接口
      hasGoodsFooter: true, // 是否需要底部按钮默认true
      goodsSearchDialog: {
        inline: true,
        formDesc: {
          goodsCode: {
            type: "input",
            layout: 8,
            label: $i18n.t("mesRequirePlan.goodsCode"),
          },
          goodsName: {
            type: "input",
            layout: 8,
            label: $i18n.t("mesRequirePlan.goodsName"),
          },
        },
      },
      goodsDialogColumn: [
        {
          type: "selection",
          fixed: "left",
        },
        {
          type: "index",
          label: $i18n.t("common.order"),
          width: 60,
          fixed: "left",
        },
        // {
        //   prop: "erpMaterialId",
        //   label: "erp物料id",
        // },
        {
          prop: "goodsCode",
          label: $i18n.t("mesRequirePlan.goodsCode"),
          width: 180,
          showOverflowTooltip: true,
          fixed: "left",
        },
        {
          prop: "goodsName",
          label: $i18n.t("mesRequirePlan.goodsName"),
          width: 180,
          showOverflowTooltip: true,
        },
        {
          prop: "goodsDesc",
          label: $i18n.t("mesRequirePlan.goodsDesc"),
          width: 180,
          showOverflowTooltip: true,
        },
        // {
        //   prop: "yardsSixNine",
        //   label: "69码",
        //   width: 150,
        //   showOverflowTooltip: true,
        // },
        {
          prop: "seriesCode",
          label: $i18n.t("mesRequirePlan.seriesCode"),
          width: 120,
          showOverflowTooltip: true,
        },
        {
          prop: "seriesName",
          label: $i18n.t("mesRequirePlan.seriesName"),
          width: 180,
          showOverflowTooltip: true,
        },

        {
          prop: "unit",
          label: $i18n.t("mesRequirePlan.unit2"),
          width: 150,
          showOverflowTooltip: true,
        },
        {
          prop: "specification",
          label: $i18n.t("mesRequirePlan.specification"),
          width: 150,
          showOverflowTooltip: true,
        },
        {
          prop: "gbCode",
          label: $i18n.t("mesRequirePlan.gbCode"),
          width: 150,
          showOverflowTooltip: true,
        },
        {
          prop: "remark",
          label: $i18n.t("mesRequirePlan.remark"),
          width: 150,
          showOverflowTooltip: true,
        },
      ],
    };
  },
  methods: {
    // 弹框表格，双击表格，或者点击确定 返回选中数据
    async getSelectBaseGoods(data) {
      //删除备注
      (data || []).map((ite) => {
        delete ite.remark;
      });
      // 筛选重复值,插入
      let list = [...data, ...(this.formDataDialog.mesRequirePlanList || [])];

      let arr = uniqueKey(list, "goodsCode");
      // arr.map((x) => {
      //   x.remark = null;
      // });
      // 筛选重复值,插入
      this.$set(this.formDataDialog, "mesRequirePlanList", arr);
      console.log(6789, arr);
      this.$set(this.editFormDataDialog, "prodCode", data[0].goodsCode);
      this.$set(this.editFormDataDialog, "prodName", data[0].goodsName);
      this.$set(this.editFormDataDialog, "seriesCode", data[0].seriesCode);
      this.$set(this.editFormDataDialog, "seriesCode", data[0].seriesName);
    },
  },
};
